package com.example.pilipili.controller;


import com.example.pilipili.common.R;
import com.example.pilipili.pojo.entity.Privileges;
import com.example.pilipili.pojo.entity.Tag;
import com.example.pilipili.service.PrivilegesService;
import com.example.pilipili.service.TagService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liyv
 * @since 2023-12-01
 */
@RestController
@RequestMapping("/privileges")
public class PrivilegesController {

    @Autowired
    PrivilegesService privilegesService ;

    /**
     * 新增权限
     * @param privileges 必选：name,description
     * @return
     */
    @PostMapping()
    public R<Privileges> save(@RequestBody @Valid Privileges privileges){
        return privilegesService.add(privileges) ;
    }

    /**
     * 删除权限
     * @param pid privilegesId
     * @return null
     */
    @DeleteMapping("/{pid}")
    public R del(@PathVariable Integer pid) {
        privilegesService.removeById(pid) ;
        return R.ok() ;

    }

    /**
     * 获取所有权限
     * @return list Privileges
     */
    @GetMapping()
    public R<List<Privileges>> getAll(){
        return R.ok(privilegesService.list());
    }

    /**
     * 修改权限
     * @param privileges 可选：name,description
     * @return
     */
    @PutMapping()
    public R<Privileges> updateById(@RequestBody @Valid Privileges privileges) {
        return privilegesService.update(privileges) ;
    }

}

